-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle conversion of custom use types for files #4225
Conversation
* adjust approach to converting files * add custom query find_file_metadata_by_use which is a valkyrie replacement for af object filter_files_by_type * add helper methods original_file, extracted_text, and thumbnail in FileSet resource Co-authored-by: cjcolvar <cjcolvard@indiana.edu>
Refactor file use: * added methods to Hyrax::FileSet defining which Valkyrie::Vocab::PCDMUse URIs should be used in all cases for the primary uses of original_file, extracted_text, and thumbnail. * updated all uses of Valkyrie::Vocab::PCDMUse URIs for the primary uses to use the methods defined in FileSet Added tests for new methods
Instead of putting the use in a use attributes, conversion from AF File copies over all types as they exist in AF into the types attribute of FileMetadata. To find the use, the :include? method is used to check for a specific use in the types. This avoids data duplication by not having both type and use. And it avoids data integrity issues when we aren’t able to correctly identify the use out of the array of types. Co-authored-by: cjcolvar <cjcolvard@indiana.edu>
…xt, thumbnail 2 changes here… ### Parts of FileSet AF behavior #original_file, #extracted_text, and #thumbnail each return a single PCDM::File, So this now has the methods that get these relatiionships from FileMetadata to return `.first` ### Versioning Versioning was looking through to ActiveFedora through the original_file method defined in wings/hydra/pcdm/pcdm_valkyrization_behavior. Since that was method was removed with the addition of Hyrax::FileSet#original_file, it was no longer getting the lookthrough behavior. The tests related to versioning have been marked pending. Issue #3923 addresses FileMetadata and versioning.
I looked through this and it looked good to me. Only thing I could find was there maybe a different way to populate an array of values possibly using #each_with_object and populating the new object with the files. But thats more of a style like preference. Thats the line I was looking at. If someone else looks at it and finds anything, otherwise I say good to go after my one comment is addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving this and will look to merge when WIP is removed and small comments are addressed
6f8864c
to
a0fa358
Compare
app/models/hyrax/file_metadata.rb
Outdated
@@ -76,19 +76,19 @@ def self.for(file:) | |||
new(label: file.original_filename, | |||
original_filename: file.original_filename, | |||
mime_type: file.content_type, | |||
use: file.try(:use) || [::Valkyrie::Vocab::PCDMUse.OriginalFile]) | |||
type: file.try(:type) || [Hyrax::FileSet.original_file_use]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use a Dry::Struct/Types default here? something like attribute :type, ::Valkyrie::Types::Set, default: [Hyrax::FileSet.original_file_use]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requested code change to use each_with_object was expanded to include all places where the pattern applied in the effected file. This also includes requested change to case statement.
a0fa358
to
c8e91a5
Compare
NOTE: PR #4215 is working toward similar issues around use types. Both approaches need to be reviewed for compatibility.
Fixes #4203
Co-authored-by: cjcolvar cjcolvard@indiana.edu
Conversion of files with custom use type
Conversion of the 3 primary use types were handled in PR #4055. That made use of the AF association target. That does not work for custom file. This PR includes a generalized approach that works for all relationships.
Refactor: type instead of use
There is no conversion path from
pcdm_file.metadata_node.type
as used in AF tofiile_metadata.use
in FileMetadata.metadata_node.type is an ActiveTriples::Relation that includes all RDF types for the file, not just the use type. For example...
The only part of this that is the use is the last one ending in
#OriginalFile
. We could have search the types for one beginning withhttp://pcdm.org/use
, but there is not a guarantee that a site wouldn't have custom uses defined that do not begin with this.For backward compatibility, we decided to remove the
use
attribute from FileMetadata and replace it withtype
.To support functionality like #original_file, we added a custom query
find_many_file_metadata_by_use(resource:, use:)
to FindFileMetadata. Then we defined methods #original_file, #extracted_text, and #thumbnail in Hyrax::FileSet using the new custom query to locate the file with the corresponding use.Refactor: Centralize definition of 3 primary file use types
In making changes to for this PR, we noticed that there were differing URIs used for the 3 primary file use types (i.e., original_file, extracted_text, and thumbnail). To address this, we centralized the definition of the primary uses in Hyrax::FileSet. All references to the associated use URIs were updated to use Hyrax::FileSet.original_file_use, Hyrax::FileSet.extracted_text_use, and Hyrax::FileSet.thumbnail.